<?php session_start(); $_SESSION['page'] = 'catalog';?>
<?php
    $category = $_GET['category'];
    $searchtext = $_GET['searchtext'];
    $libraryNo = $_COOKIE['libraryNo'];
    //$location = $_GET['location'];
    require('db_connection.php');
    
if($category != 'All')
    {
      $query = "SELECT * FROM tblcollection  WHERE libraryNo LIKE '$libraryNo' AND $category LIKE '%$searchtext%' ";
    }
    elseif ($category == 'All' && $searchtext == 'All' || $searchtext == 'all' )
   {
        $query = "SELECT * FROM tblcollection WHERE libraryNo LIKE '$libraryNo'";
   }
  else
  {
    //$query= "SELECT * FROM tblcollection WHERE libraryNo='$libraryNo' AND title LIKE '%$searchtext%' OR author LIKE '%$searchtext%' OR subject LIKE '%$searchtext%' ";
    $query = "SELECT * FROM tblcollection WHERE title LIKE '%$searchtext%' OR author LIKE '%$searchtext%' OR subject LIKE '%$searchtext%' OR description LIKE '%$searchtext%'AND libraryNo LIKE '$libraryNo'";
  }

  $result = mysql_query($query);
?>

<!doctype html public "-//W3C//DTD HTML 4.01//EN">

<html>

   <head>
      <title>Catalog Search Result</title>
      <meta http-equiv="generator" content="PHP Designer 2005" />
      <style type="text/css">
        @import url(style.css);
      </style>
   </head>
   <script LANGUAGE=javascript>
       <!--
     function check()
     {
        if(document.search_form.searchtext.value=="" )
        {
          alert('Please fill the search box.');
          return false;
        }
        return true;
     }
     //-->
    </script>

   <body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000" class=''>

   <form method='get' action='catalogresult.php' name='search_form' onSubmit="return check();">
   <table border='0' width='80%' align='center' class='content'>
        <tr><td colspan='2'><img src='images/banner1.jpg'></td></tr>
            <tr><td align='right' colspan='2' class='logout'><?php require ('loginout.php');?></td></tr>
            <tr class='menuborder'><td width='90%'><img src='images/searchresult.png'></td><td><?php  require('buttons.php'); ?></td></tr>
            <tr><td colspan='2' class='bodyborder'>
            <table align='center'>
                <tr><td height='30'></td></tr>
                <tr><td>Search By</td>
                    <td><select name='category'>
                        <option>All</option>
                        <option>Title</option>
                        <option>Author</option>
                        <option>Subject</option>
                        <option>Keyword</option>
                        </select>
                    </td>
                    <td><input type='text' name='searchtext' size='40'></td>
                    <td><input type='submit' class='tool' value='Search'></td>
                </tr>
                <tr><td height='30'></td></tr>
            </table>
            </td>
        </tr>
        <tr><td colspan='2' class='bodyborder'>
            <table align='center' border='0' width='70%'>
                <tr><th colspan='4'>Search Result</th></tr>
                <tr><td height='15'></td></tr>
                <tr>
                <td>
                <?php
                $ctr=1;
                while ($row = mysql_fetch_array($result))
                {
                    $libraryNoBook = $row['libraryNo'];
                    if($libraryNoBook == $libraryNo)
                    {
                        $title=$row['title'];
                        $author = $row['author'];
                        $publisher = $row['publisher'];
                        $materialID = $row['materialID'];
                        echo"<tr class='td1'><td>".$ctr.".  <a href='editcatalog.php?materialID=$materialID'> ".$title."</a></td></tr>";
                        echo"<tr class='td2'><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;by &nbsp;".$author.", ".$publisher."</td></tr>";
                        echo"</tr>";
                        $ctr++;
                    }
                    
                }
                mysql_close();
                ?>

                </td>
                </tr>
            <tr><td height='30'></td></tr>
            </table>
            </td>
        </tr>
        <tr><td align='center' colspan='2'><?php require ('copyright.php')?></td></tr>
    </form>

   </body>
</html>
